package com.neo.mapper;

import com.neo.domain.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: hredis
 * @Date: 2020/10/24 19:56
 */
public interface EmployeeMapper {

    /**
     *  查询所有
     * @return 雇员集合
     */
    @Select("select id, last_name, email, gender, age from tbl_employee")
    //对一、对多查询
    /*
    @Results(
            value = {
                    @Result(column = "deptId", property = "dept", one = @One(select = "com.neo.mapper.DeptMapper.findById")),
                    @Result(property = "posts", many = @Many(select = "com.neo.mapper.PostMapper.findPostsByEmpId", fetchType = FetchType.LAZY)),
            }
    )
    */
    List<Employee> selectAll();

    /**
     * 雇员添加
     * @param employee
     */
    @Insert("INSERT INTO `test`.`tbl_employee` (`last_name`, `email`, `gender`, `age`) VALUES (#{lastName}, #{email}, #{gender}, #{age});")
    @SelectKey(before = false,keyColumn = "id",keyProperty = "id",  statement = "select last_insert_id()",resultType = Integer.class)
    void add(Employee employee);

    /**
     * 雇员更新
     * @param employee
     */
    @UpdateProvider(type = EmployeeMapperProvider.class, method = "updateEmployeeById")
    void update(Employee employee);

    /**
     * 雇员查询byId
     * @param id
     * @return
     */
    @Select("select * from tbl_employee where id = #{id}")
    Employee findById(@Param("id") Integer id);

    /**
     * 雇员删除byId
     * @param id
     */
    @Delete("delete from tbl_employee where id = #{id}")
    void deleteById(@Param("id") Integer id);


    /**
     * 根据条件查询
     * @param queryString
     * @return
     */
    @SelectProvider(type = EmployeeMapperProvider.class, method = "findByCondition")
    List<Employee> findByCondition(@Param("queryString") String queryString);
}